package indi.caibo.oss.controller;

import indi.caibo.commonutils.R;
import indi.caibo.oss.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Bo Cai
 * @version 1.0
 * @date 2021/10/5 22:09
 */
@Api(tags = "阿里云文件管理模块")
@RestController
@RequestMapping("/admin/oss/file")
public class FileController {
    @Autowired
    private FileService fileService;

    @PostMapping("upload")
    @ApiOperation("上传文件到阿里云oss")
    public R upload(@ApiParam(name = "file", value = "文件", required = true)
                    @RequestPart("file") MultipartFile file,
                    @ApiParam(name = "host", value = "文件上传路径", required = false) String host) {
        String uploadUrl = fileService.upload(file);
        //返回r对象
        return R.ok().message("文件上传成功").data("url", uploadUrl);
    }
}
